<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
  <meta name="description" content="API docs for the StreamController constructor from the Class StreamController class from the dart:async library, for the Dart programming language.">
  <title>StreamController constructor - StreamController class - dart:async library - Dart API</title>
  <!-- required because all the links are pseudo-absolute -->
  <base href="../..">

  <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" href="static-assets/github.css">
  <link rel="stylesheet" href="static-assets/styles.css">
  <link rel="icon" href="static-assets/favicon.png">
  
</head>

<body>

<div id="overlay-under-drawer"></div>

<header id="title">
  <button id="sidenav-left-toggle" type="button">&nbsp;</button>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="index.html">shake</a></li>
    <li><a href="dart-async/dart-async-library.html">dart:async</a></li>
    <li><a href="dart-async/StreamController-class.html">StreamController<span class="signature">&lt;<wbr><span class="type-parameter">T</span>&gt;</span></a></li>
    <li class="self-crumb">StreamController factory constructor</li>
  </ol>
  <div class="self-name">StreamController</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<main>

  <div id="dartdoc-sidebar-left" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
    <header id="header-search-sidebar" class="hidden-l">
      <form class="search-sidebar" role="search">
        <input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
      </form>
    </header>
    
    <ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
      <li><a href="index.html">shake</a></li>
      <li><a href="dart-async/dart-async-library.html">dart:async</a></li>
      <li><a href="dart-async/StreamController-class.html">StreamController<span class="signature">&lt;<wbr><span class="type-parameter">T</span>&gt;</span></a></li>
      <li class="self-crumb">StreamController factory constructor</li>
    </ol>
    
    <h5>StreamController class</h5>
    <ol>
      <li class="section-title"><a href="dart-async/StreamController-class.html#constructors">Constructors</a></li>
      <li><a href="dart-async/StreamController/StreamController.html">StreamController</a></li>
      <li><a href="dart-async/StreamController/StreamController.broadcast.html">broadcast</a></li>
    
      <li class="section-title">
        <a href="dart-async/StreamController-class.html#instance-properties">Properties</a>
      </li>
      <li><a href="dart-async/StreamController/hasListener.html">hasListener</a></li>
      <li><a href="dart-async/StreamController/isClosed.html">isClosed</a></li>
      <li><a href="dart-async/StreamController/isPaused.html">isPaused</a></li>
      <li><a href="dart-async/StreamController/onCancel.html">onCancel</a></li>
      <li><a href="dart-async/StreamController/onListen.html">onListen</a></li>
      <li><a href="dart-async/StreamController/onPause.html">onPause</a></li>
      <li><a href="dart-async/StreamController/onResume.html">onResume</a></li>
      <li><a href="dart-async/StreamController/sink.html">sink</a></li>
      <li><a href="dart-async/StreamController/stream.html">stream</a></li>
      <li class="inherited"><a href="dart-async/StreamSink/done.html">done</a></li>
      <li class="inherited"><a href="dart-core/Object/hashCode.html">hashCode</a></li>
      <li class="inherited"><a href="dart-core/Object/runtimeType.html">runtimeType</a></li>
    
      <li class="section-title"><a href="dart-async/StreamController-class.html#instance-methods">Methods</a></li>
      <li><a href="dart-async/StreamController/add.html">add</a></li>
      <li><a href="dart-async/StreamController/addError.html">addError</a></li>
      <li><a href="dart-async/StreamController/addStream.html">addStream</a></li>
      <li><a href="dart-async/StreamController/close.html">close</a></li>
      <li class="inherited"><a href="dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
      <li class="inherited"><a href="dart-core/Object/toString.html">toString</a></li>
    
      <li class="section-title inherited"><a href="dart-async/StreamController-class.html#operators">Operators</a></li>
      <li class="inherited"><a href="dart-core/Object/operator_equals.html">operator ==</a></li>
    
    
    
    </ol>
  </div><!--/.sidebar-offcanvas-left-->

  <div id="dartdoc-main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
      <div><h1>StreamController&lt;<wbr><span class="type-parameter">T</span>&gt; constructor</h1></div>

    <section class="multi-line-signature">
      
      <span class="name ">StreamController&lt;<wbr><span class="type-parameter">T</span>&gt;</span>(<wbr>{<span class="parameter" id="-param-onListen"><span class="type-annotation">void</span> <span class="parameter-name">onListen</span>(), </span> <span class="parameter" id="-param-onPause"><span class="type-annotation">void</span> <span class="parameter-name">onPause</span>(), </span> <span class="parameter" id="-param-onResume"><span class="type-annotation">void</span> <span class="parameter-name">onResume</span>(), </span> <span class="parameter" id="-param-onCancel"><span class="type-annotation">dynamic</span> <span class="parameter-name">onCancel</span>(), </span> <span class="parameter" id="-param-sync"><span class="type-annotation"><a href="dart-core/bool-class.html">bool</a></span> <span class="parameter-name">sync</span>: <span class="default-value">false</span></span> })
    </section>

    <section class="desc markdown">
      <p>A controller with a <a href="dart-async/StreamController/stream.html">stream</a> that supports only one single subscriber.</p>
<p>If <code>sync</code> is true, the returned stream controller is a
<a href="dart-async/SynchronousStreamController-class.html">SynchronousStreamController</a>, and must be used with the care
and attention necessary to not break the <a href="dart-async/Stream-class.html">Stream</a> contract. If in doubt,
use the non-sync version.</p>
<p>Using an asynchronous controller will never give the wrong
behavior, but using a synchronous controller incorrectly can cause
otherwise correct programs to break.</p>
<p>A synchronous controller is only intended for optimizing event
propagation when one asynchronous event immediately triggers another.
It should not be used unless the calls to <a href="dart-async/StreamController/add.html">add</a> or <a href="dart-async/StreamController/addError.html">addError</a>
are guaranteed to occur in places where it won't break <code>Stream</code> invariants.</p>
<p>Use synchronous controllers only to forward (potentially transformed)
events from another stream or a future.</p>
<p>A Stream should be inert until a subscriber starts listening on it (using
the <code>onListen</code> callback to start producing events). Streams should not
leak resources (like websockets) when no user ever listens on the stream.</p>
<p>The controller buffers all incoming events until a subscriber is
registered, but this feature should only be used in rare circumstances.</p>
<p>The <code>onPause</code> function is called when the stream becomes
paused. <code>onResume</code> is called when the stream resumed.</p>
<p>The <code>onListen</code> callback is called when the stream
receives its listener and <code>onCancel</code> when the listener ends
its subscription. If <code>onCancel</code> needs to perform an asynchronous operation,
<code>onCancel</code> should return a future that completes when the cancel operation
is done.</p>
<p>If the stream is canceled before the controller needs new data the
<code>onResume</code> call might not be executed.</p>
    </section>
    
    <section class="summary source-code" id="source">
      <h2><span>Implementation</span></h2>
      <pre class="language-dart"><code class="language-dart">factory StreamController(
    {void onListen(),
    void onPause(),
    void onResume(),
    onCancel(),
    bool sync: false}) {
  return sync
      ? new _SyncStreamController&lt;T&gt;(onListen, onPause, onResume, onCancel)
      : new _AsyncStreamController&lt;T&gt;(onListen, onPause, onResume, onCancel);
}</code></pre>
    </section>

  </div> <!-- /.main-content -->

  <div id="dartdoc-sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
  </div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    shake 0.1.0
  </span>

  
</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="static-assets/typeahead.bundle.min.js"></script>
<script src="static-assets/highlight.pack.js"></script>
<script src="static-assets/URI.js"></script>
<script src="static-assets/script.js"></script>


</body>

</html>
